SPDE Toy Example

Toy dataset from Blangiardo and Cameletti (2015).

# Plot the data.
plot(s2 ~ s1, col = rgb(SPDEtoy$y / max(SPDEtoy$y), 0, 0), data = SPDEtoy,
     pch = 19, asp = 1, main = 'Toy Data')

# Create a mesh for the SPDE method and then plot it.
toymesh <- inla.mesh.2d(as.matrix(SPDEtoy[,c('s1', 's2')]),
                        max.edge = c(0.1, 0.2))
plot(toymesh, asp = 1)
points(SPDEtoy$s1, SPDEtoy$s2, col = rgb(SPDEtoy$y / max(SPDEtoy$y), 0, 0, 0.5),
       pch = 19)

# Initialize SPDE projector matrix.
toyA <- inla.spde.make.A(toymesh, as.matrix(SPDEtoy[,c('s1', 's2')]))

# Initialize exponential covariance structure for SPDE.
toyspde <- inla.spde2.matern(toymesh, alpha = 2)

# Fit the model with INLA.
# Can't find the intercept??
toyfit <- inla(
#  y ~ -1 + intercept + f(spatial_field, model = toyspde),
  y ~ f(spatial_field, model = toyspde),
  data = list(
    y = SPDEtoy$y,
    intercept = rep(1, nrow(SPDEtoy)),
    spatial_field = seq_len(nrow(SPDEtoy))
  )#,
#  control.predictor = list(A = toyA, compute = TRUE)
)

Bei Dataset

Example from Møller and Waagepetersen (2007), Beilschmiedia pendula Lauraceae locations in a plot in Panama. bei dataset in spatstat (Baddeley and Turner 2005).

# Plot the full point pattern.
plot(bei, pch = '.', cols = 'black', main = 'Realized Point Pattern')

beimesh <- inla.mesh.2d(cbind(bei$x, bei$y), cutoff = 1, max.edge = c(10, 20))
plot(beimesh, asp = 1)

bei_spdf <- as.SpatialPoints.ppp(bei)
# Need mesh and prior for GP.
#bei_lgcp <- lgcp(, data = bei_spdf)
# Take a sample of quadrats and plot the observed point pattern.
set.seed(84323)
n_quads <- 10
botleft <- cbind(runif(n_quads, 0, 950), runif(n_quads, 0, 450))
bei_win <- do.call(
  union.owin,
  apply(botleft, 1, function(x){return(
    owin(x[1] + c(0, 50), x[2] + c(0, 50))
  )})
)
bei_samp <- bei[bei_win]
bei_window_full <- Window(bei)

plot(bei_window_full, main = 'Observed Subset')
plot(bei_win, add = TRUE)
plot(bei_samp, pch = '.', cols = 'black', add = TRUE)

beisampmesh <- inla.mesh.2d(cbind(bei_samp$x, bei_samp$y),
                            cutoff = 1, max.edge = c(10, 20), offset = 100)
plot(beisampmesh, asp = 1)
plot(bei_window_full, border = 'red', add = TRUE)

References

Baddeley, Adrian, and Rolf Turner. 2005. “Spatstat: An R Package for Analyzing Spatial Point Patterns.” Journal of Statistical Software 12 (6): 1–42.

Blangiardo, Marta, and Michela Cameletti. 2015. Spatial and Spatio-Temporal Bayesian Models with R-INLA. Wiley.

Møller, J, and RP Waagepetersen. 2007. “Modern Spatial Point Process Modelling and Inference.” Scandinavian Journal of Statistics 34: 643–711.